﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SuperQuery.UserControls.ToolBars
{
    /// <summary>
    /// Interaction logic for QueryToolBar.xaml
    /// </summary>
    public partial class QueryToolBar : ToolBarBase
    {
        /// <summary>
        /// Initialise the Query Toolbar
        /// </summary>
        public QueryToolBar()
        {
            InitializeComponent();

            // Set intial state of toolbar buttons
            EnabledChanged(null, null);
        }

        /// <summary>
        /// Event raised when the enabled property is changed
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        protected override void EnabledChanged(object sender, EventArgs e)
        {
            bool isEnabled = Enabled;
            btnRunAll.IsEnabled = isEnabled;
            btnRunSelected.IsEnabled = isEnabled;
            btnStop.IsEnabled = !isEnabled;
            cboTypeOfQuery.IsEnabled = isEnabled;
            txtTimeOut.IsEnabled = isEnabled;
        }

        /// <summary>
        /// Raise an event to signal that the user wants to run the current query against all databases
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void btnRunAll_Click(object sender, RoutedEventArgs e)
        {
            OnToolBarOperation(ToolBarButtons.RunAll);
        }

        /// <summary>
        /// Raise an event to signal that the user wants to run the current query against selected databases only
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void btnRunSelected_Click(object sender, RoutedEventArgs e)
        {
            OnToolBarOperation(ToolBarButtons.RunSelected);
        }

        /// <summary>
        /// Raise an event to signal that the user wants to stop the current query from executing
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            OnToolBarOperation(ToolBarButtons.Stop);
        }
    }
}
